﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.sjsbyes
{
    public partial class TZGGList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_buildGrid();
            }
        }
        protected void f_buildGrid()
        {
            Hashtable htable = new Hashtable();
            htable.Add("@BTSBLMName","1");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_news_all");

            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dbRow in ds.Tables[0].Rows)
                    {
                        if (dbRow["EditUrl"] != null)
                        {
                            dbRow["EditUrl"] = "newslist.aspx?Command=Edit";
                        }

                        if (dbRow["ViewUrl"] != null)
                        {
                            dbRow["ViewUrl"] = "newslist.aspx?Command=View";
                        }
                        string s = dbRow["BTSBLMName"].ToString();
                        switch (s)
                        {
                            case "1":
                                dbRow["title"] = "通知公告";
                                break;
                            case "2":
                                dbRow["title"] = "工作动态";
                                break;
                            case "3":
                                dbRow["title"] = "经验交流";
                                break;
                            case "4":
                                dbRow["title"] = "调研报告";
                                break;
                            case "5":
                                dbRow["title"] = "工作简报";
                                break;
                        }
                    }
                }
                PostListS.DataSource = ds;
                PostListS.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

            }
        }
        /// <summary>
        /// Callback异步加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            SqlReadXml org = new SqlReadXml();
            try
            {
                #region 删除数据
                if (Usual.f_convertString(e.Parameters[0]) == "3")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();
                        base.o_uiTable.Add("@NewsID", zid);

                        //先查找有无子部门


                        //删除此部门
                        if (deptname == "")
                        {
                            Org.NotDoSQL("del_news_byid", base.o_uiTable);
                            hfError.Value = lblProcesserMsg.Text = "删除数据成功!";
                        }
                        this.f_buildGrid();
                    }
                    catch (System.Exception ee)
                    {
                        hfError.Value = lblProcesserMsg.Text = "删除数据失败!" + ee.Message;

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "2")
                {
                    SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);
                    if (zid == "" || zid == null)
                    {
                        this.f_buildGrid();
                    }
                    else
                    {
                        string likes = e.Parameters[2].ToString().Trim();
                        likes = "%" + likes + "%";
                        Hashtable htable = new Hashtable();
                        htable.Add("@like", likes);
                        htable.Add("@BTSBLMName","1");
                        DataSet ds = Org.ReaderDataSet("sel_news_bylike", htable);
                        if (ds != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dbRow in ds.Tables[0].Rows)
                                {
                                    if (dbRow["EditUrl"] != null)
                                    {
                                        dbRow["EditUrl"] = "newslist.aspx?Command=Edit";
                                    }

                                    if (dbRow["ViewUrl"] != null)
                                    {
                                        dbRow["ViewUrl"] = "newslist.aspx?Command=View";
                                    }
                                    string s = dbRow["BTSBLMName"].ToString();
                                    switch (s)
                                    {
                                        case "1":
                                            dbRow["title"] = "通知公告";
                                            break;
                                        case "2":
                                            dbRow["title"] = "工作动态";
                                            break;
                                        case "3":
                                            dbRow["title"] = "经验交流";
                                            break;
                                        case "4":
                                            dbRow["title"] = "调研报告";
                                            break;
                                        case "5":
                                            dbRow["title"] = "工作简报";
                                            break;
                                    }
                                }
                            }
                        }
                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "sel")
                { 
                     SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);

                        string likes = e.Parameters[1].ToString().Trim();
                        likes = "%" + likes + "%";
                        Hashtable htable = new Hashtable();
                        htable.Add("@like", likes);
                        string zzs = e.Parameters[2].ToString().Trim();
                        zzs = "%"+zzs+"%";
                        string fbs = e.Parameters[3].ToString().Trim();
                        fbs = "%" + fbs + "%";
                        string cont = e.Parameters[4].ToString().Trim();
                        cont = "%" + cont + "%";
                        htable.Add("@NewsZZ", zzs);
                        htable.Add("@FBdate",fbs);
                        htable.Add("@Newscontent",cont);
                        htable.Add("@BTSBLMName","1");

                        DataSet ds = Org.ReaderDataSet("sel_news_bylikes", htable);
                        if (ds != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dbRow in ds.Tables[0].Rows)
                                {
                                    if (dbRow["EditUrl"] != null)
                                    {
                                        dbRow["EditUrl"] = "newslist.aspx?Command=Edit";
                                    }

                                    if (dbRow["ViewUrl"] != null)
                                    {
                                        dbRow["ViewUrl"] = "newslist.aspx?Command=View";
                                    }
                                    string s = dbRow["BTSBLMName"].ToString();
                                    switch (s)
                                    {
                                        case "1":
                                            dbRow["title"] = "通知公告";
                                            break;
                                        case "2":
                                            dbRow["title"] = "工作动态";
                                            break;
                                        case "3":
                                            dbRow["title"] = "经验交流";
                                            break;
                                        case "4":
                                            dbRow["title"] = "调研报告";
                                            break;
                                        case "5":
                                            dbRow["title"] = "工作简报";
                                            break;
                                    }
                                }
                            }
                        }
                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                    }
                
       
                #endregion

            }
            catch (System.Exception pexp)
            {
                throw (pexp);
            }
            //最后进行Grid数据查询并填充
            finally
            {

                LPanel.RenderControl(e.Output);
            }
        }
    }
}